<template>
    <div>
        <div style=" float: right;margin-right: 20px;">
            <el-button type="warning" size="mini" id="audit" @click="audit()"><i class="el-icon-finished"></i>审批</el-button>
            <br/>
            <el-button style="margin-top: 10px;" type="warning" size="mini" id="withdraw" @click="withdraw"><i
                    class="el-icon-back"></i>撤回
            </el-button>
            <br/>
            <el-button style="margin-top: 10px;" type="success" size="mini" id="printBtn" v-print="printObj"><i class="el-icon-printer"></i>打印</el-button>
        </div>

        <form class="wrapper" id="wrapperInboundOrderTable" style="font-size: 14px">
            <div class="header">
                <img src="/image/logo.jpg" /><label>固基行远，协晨悟通</label>
            </div>
            <h2 class="Title">固远晨通科技发展有限公司入库单</h2>
            <table class="report_data" rules=all>
                <thead style="border-color: #999999;text-align: left">
                <tr>
                    <th class="tableDataTh" colspan="8">
                        <label class="tableTitle">入库单号：</label>
                        <span style="margin-left: 10px">{{ InboundOrderDetalis.InboundNumber }}</span>
                    </th>
                    <th class="tableDataTh" colspan="8">
                        <label class="tableTitle">经办人：</label>
                        <span style="margin-left: 10px">{{ GetUserName(InboundOrderDetalis.OperatId) }}</span>
                    </th>
                    <th class="tableDataTh" colspan="8">
                        <label class="tableTitle">入库日期：</label>
                        <span style="margin-left: 10px">{{ InboundOrderDetalis.OperatDate }}</span>
                    </th>
                </tr>
                <tr>
                    <th class="tableDataTh" colspan="8">
                        <label class="tableTitle">费用总计（小写）：</label>
                        <span style="margin-left: 10px">￥{{ Capitalion }}</span>
                    </th>
                    <th class="tableDataTh" colspan="8">
                        <label class="tableTitle">人民币（大写）：</label>
                        <span style="margin-left: 10px">{{ CapitalionChinese }}</span>
                    </th>
                    <th class="tableDataTh" colspan="8">
                        <label class="tableTitle">备注：</label>
                        <span style="margin-left: 10px">{{ InboundOrderDetalis.Remark || "无" }}</span>
                    </th>
                </tr>
                </thead>
            </table>
            <div style="border-left: #999999 2px solid;border-right: #999999 2px solid">
                <h2 style="text-align: center">物资列表</h2>
            </div>
            <table class="report_data" rules=all>
                <tr>
                    <th>序号</th>
                    <th>名称</th>
                    <th>规格型号</th>
                    <th>数量</th>
                    <th>单位</th>
                    <th>单价</th>
                    <th>复核总价</th>
                    <th>实际总价</th>
                    <th>部门</th>
                    <th>项目</th>
                    <th>供应商</th>
                </tr>
                <tr v-for="(d,i) in tableData">
                    <td>{{ i+1 }}</td>
                    <td>{{ d.DeviceName }}</td>
                    <td>{{ d.DeviceModel  }}</td>
                    <td>{{ d.Amount  }}</td>
                    <td>{{ d.Unit   }}</td>
                    <td>{{ d.Price   }}</td>
                    <td>{{ d.ReviewTotalPrice   }}</td>
                    <td>{{ d.TotalPrice   }}</td>
                    <td>{{ GetDepartmentName(d.DepartmentId)  }}</td>
                    <td style="max-width: 300px">{{ GetProjectName(d.ProjectId) }} </td>
                    <td>{{ GetCustomerName(d.VendorInf) }}  </td>
                </tr>
            </table>
            <div style="border-left: #999999 2px solid;border-right: #999999 2px solid">
                <h2 style="text-align: center">审批流程</h2>
            </div>
            <table class="report_audit" rules=all>
                <tbody id="auditPeople"></tbody>
            </table>
            <div class="author"><span>固远晨通科技发展有限公司制</span></div>
            <div id="Footer">
                <div><span style="margin-right: 100px;">固远晨通科技发展有限公司</span><span>网址：<a>www.guyuanct.com</a></span></div>
                <div><span>地址：成都西区大道199号成都模具工业园C1栋</span></div>
            </div>
        </form>

        <el-dialog v-if="AuditComment_show" :modal="false"  :visible.sync="AuditComment_show" width="40%" title="审批"  :before-close="onClose">
            <AuditComment ref="AuditCommentRef" :approval-receipt="Approval_event" :approval="Approval"></AuditComment>
        </el-dialog>

    </div>
</template>

<script>
    import * as publicjs from '/public/Scriput/Public'
    import AuditComment from "../../AuditComment";

    export default {
        name: "InboundOrderTable",
        components: {
            'AuditComment': AuditComment
        },
        props: {
            ids: {
                type: Array,
                required: true
            },
            InboundOrderDetalis: {
                type: Object,
                required: true
            },
            auditRule: {
                type: Object,
                required: true
            },
            AllProject: {
                type: Array,
                required: true
            },
            AllDepartment: {
                type: Array,
                required: true
            },
            AllCustomer: {
                type: Array,
                required: true
            },
        },
        data() {
            return {
                //表格数据
                tableData: [],
                //总价
                Capitalion: 0,
                //总价汉字大写
                CapitalionChinese: '',
                //审批弹框
                AuditComment_show: false,
                // 审批弹窗返回数据
                Approval: {
                    State: 1,
                    Comment: '',
                },
                printObj: {
                    id: "wrapperInboundOrderTable",  //打印标签的id
                    popTitle: '',  //文件标题
                },
            }
        },
        created() {
            // 注入AllUsers数据
            publicjs.getAllUsers(this.$store.state.AllUsers)
        },
        watch: {
            ids: function (ids) {
                this.Capitalion = 0
                this.CapitalionChinese = ''
                this.$http.post('Report/GetDetialInboundRecord', ids).then(res => {
                    this.tableData = res.data
                    this.tableData.forEach(item => {
                        this.Capitalion = publicjs.dcmAdd(this.Capitalion, item.TotalPrice)
                    })
                    this.CapitalionChinese = publicjs.Arabia_To_SimplifiedChinese(this.Capitalion)
                    publicjs.AddAuditPeople(this.InboundOrderDetalis, null, this.auditRule)
                })
            }
        },
        methods: {
            //获取对应人员名字
            GetUserName(value) {
                let name = ''
                if (value != 0) {
                    for (let i = 0; i < this.$store.state.AllUsers.length; i++) {
                        if (this.$store.state.AllUsers[i].Id == value) {
                            name = this.$store.state.AllUsers[i].UserName
                            return name
                        }
                    }
                }
            },
            //获取对应人员名字
            GetProjectName(value) {
                let name = ''
                if (value != 0) {
                    for (let i = 0; i < this.AllProject.length; i++) {
                        if (this.AllProject[i].Id == value) {
                            name = this.AllProject[i].ProjectName
                            return name
                        }
                    }
                }
            },
            //获取对应人员名字
            GetDepartmentName(value) {
                let name = ''
                if (value != 0) {
                    for (let i = 0; i < this.AllDepartment.length; i++) {
                        if (this.AllDepartment[i].Id == value) {
                            name = this.AllDepartment[i].DepartmentName
                            return name
                        }
                    }
                }
            },
            //获取对应人员名字
            GetCustomerName(value) {
                let name = ''
                if (value != 0) {
                    for (let i = 0; i < this.AllCustomer.length; i++) {
                        if (this.AllCustomer[i].Id == value) {
                            name = this.AllCustomer[i].CustomerCompany
                            return name
                        }
                    }
                }
            },
            //审批弹框
            audit() {
                this.AuditComment_show = true
            },
            // 审批撤回
            withdraw() {
                this.$confirm('您确定要撤回吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    if (!this.$store.state.enumDes.length) {
                        this.$message.error('数据错误,请重新登录!');
                        return
                    }
                    let Modulenumber = "";
                    for (let i = 0; i < this.$store.state.enumDes.length; i++) {
                        if (this.$store.state.enumDes[i].key === "InboundOrder") {
                            Modulenumber = this.$store.state.enumDes[i].value;
                            break;
                        }
                    }
                    this.$http.post("PublicMethodApi/RevokeApproveState", {
                        FormId: this.InboundOrderDetalis.Id,
                        Modulenumber: Modulenumber,
                    }).then(res => {
                        if(res.data.Status){
                            this.$http.get('Report/InboundOrder?InboundNumber=' + this.InboundOrderDetalis.InboundNumber).then(res => {
                                if (res.data.obj != null) {
                                    publicjs.AddAuditPeople(res.data.obj, null, res.data.auditRule)
                                }
                            })
                            this.$parent.$parent.formdata()
                            this.$message.success(res.data.Message)
                        }else{
                            this.$message.error(res.data.Message)
                        }
                    }).catch(() => {
                        this.$message.error('服务器异常,请联系管理员!')
                    })
                }).catch(() => {

                })
            },
            // 关闭审批结果组件
            async onClose(done) {
                await done();
                this.$refs["AuditCommentRef"].FormClose_event();
            },
            //审批
            Approval_event() {
                let loadding = this.openLoading();
                this.$http.post('Device/AuditInboundOrder', {
                    InboundNumber: this.InboundOrderDetalis.InboundNumber,
                    State: this.Approval.State,
                    Comment: this.Approval.Comment,
                }).then(res => {
                    loadding.close();
                    if (res.data.IsSuccess) {
                        this.$http.get('Report/InboundOrder?InboundNumber=' + this.InboundOrderDetalis.InboundNumber).then(res => {
                            if (res.data.obj != null) {
                                publicjs.AddAuditPeople(res.data.obj, null, res.data.auditRule)
                            }
                        })
                        this.$parent.$parent.formdata()
                        this.$message.success(res.data.Msg)
                    } else {
                        this.$message.warning(res.data.Msg)
                    }
                    this.AuditComment_show = false
                })
                this.$refs["AuditCommentRef"].FormClose_event();
            }
        },
    }
</script>

<style scoped>
    .time{
        text-align: right;
    }
    /*外包装样式*/
    .wrapper {
        width: 80%;
        height: 100%;
        margin: auto;
    }
    /*页眉样式*/
    .header {
        font-weight: bold;
        font-size: 20px;
        font-family: cursive;
        width: 80%;
        margin: auto;
        border-bottom: 2px solid black;
        padding: 10px 0px;
        position: relative;
    }

    .header img {
        width: 200px;
        height: 55px;
    }

    .header label {
        position: absolute;
        bottom: 10px;
        right: 70px;
    }
    /*标题样式*/
    h2 {
        width: 80%;
        text-align: center;
        font-size: 25px;
        font-weight: bold;
        margin: auto;
        padding: 10px 0;
    }
    /*标题样式*/
    h4 {
        width: 80%;
        text-align: center;
        font-weight: bold;
        margin: auto;
        padding: 10px 0;
    }
    /*数据表格样式*/
    .report_data {
        width: 100%;
        text-align: center;
        border: 1px solid black;
        font-size: 14px;
        word-break: break-all;
    }
    .report_data tr {
        height: 40px;
    }
    .report_data th {
        font-weight: 100;
    }
    .baseInfo {
        height: 20px;
        line-height: 20px;
        border: 1px solid black;
        border-bottom: 0px;
        padding: 8px;
    }
    .baseInfo .worderWrapper {
        display: inline-block;
        width: 200px;
    }
    .style {
        height: 40px;
        line-height: 40px;
        border: 1px solid black;
        border-bottom: 0px;
        padding: 8px;
    }
    .price {
        border-top: none;
    }
    /*审核表格样式*/
    .report_audit {
        width: 100%;
        border: 1px solid black;
        font-size: 14px;
    }
    .report_audit .tdCenter {
        text-align: center;
    }
    .report_audit tr {
        height: 70px;
    }
    .report_audit tr p {
        padding: 3px;
    }
    .report_audit td {
        padding: 0 10px;
    }
    .report_audit td:first-child {
        width: 150px;
    }
    .report_audit .tr_center {
        text-align: center;
    }
    .audit {
        font: italic bold 20px/30px arial,sans-serif;
        text-align: right;
    }
    .audit span {
        display: inline-block;
        width: 100px;
        font: bold 17px/30px arial,sans-serif;
    }
    .author {
        width: 80%;
        margin: auto;
        margin-top: 5px;
        font-weight: bold;
        text-align: right;
    }
    /*页脚样式*/
    #Footer {
        width: 80%;
        margin: auto;
        border-top: 2px solid black;
        margin-top: 60px;
        font-weight: bold;
    }
    #Footer div {
        padding-top: 5px;
        padding-bottom: 10px;
    }
    #search select {
        text-align: left;
    }
    /*折叠面板样式修改*/
    .layui-collapse .layui-colla-title {
        margin: 0;
        width: 100%;
        text-align: left;
    }
    /*报表管理下统计报表的样式*/
    #EchartData .pie {
        height: 500px;
    }
    #EchartData .pieData {
        float: left;
        width: 50%;
        height: 500px;
    }
    #EchartData .bar {
        width: 100%;
        height: 500px;
    }
    .report_data .tr_one {
        height: 50px;
    }
    .report_data .tr_two {
        height: 100px;
    }
    .report_data .td_Title {
        font-weight: bold;
    }
    .report_data .layui-form-radio > i:hover, .report_data .layui-form-radioed > i {
        color: #5FB878 !important;
    }
</style>
